<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="icon" href="{{ url_for('static', filename='favicon.ico') }}" type="image/x-icon">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/code.css') }}">
    <script src="{{ url_for('static', filename='js/theme.js') }}" defer></script>
    <script src="{{ url_for('static', filename='js/code.js') }}" defer></script>
    <link rel="stylesheet" href="{{ url_for('static', filename='css/default.css') }}">
    <script src="{{ url_for('static', filename='js/highlight.min.js') }}"></script>
    <script>hljs.highlightAll();</script>
    <script type="text/javascript" src="{{ url_for('static', filename='js/clipboard.min.js') }}"></script>
    <title>代码块</title>
</head>
<body class="dark-mode">
    <div class="line-container">
      <h1>代码</h1>
      <img id="theme-toggle" src="{{ url_for('static', filename='icon-theme.png') }}" alt="PowerControl" class="icon-image"
        title="深色/浅色模式切换">
    </div>
{% raw %}
    <!-- 第一个代码块 -->
    <h3>1、docker-cli：</h3>
    <pre>
        <button class="copy-btn" data-clipboard-target="#code-block-1">复制代码</button>
        <code id="code-block-1">
docker run -d -v /your/path:/app/data -e WEB_PORT=7678 -e WEB_KEY=yourkey --network host --restart unless-stopped --name powercontrol viklion/powercontrol:latest
# 默认root用户运行
        </code>
    </pre>
    <pre>
        <button class="copy-btn" data-clipboard-target="#code-block-2">复制代码</button>
        <code id="code-block-2">
docker run -d -u 1000:100 -v /your/path:/app/data -e WEB_PORT=7678 -e WEB_KEY=yourkey --network host --restart unless-stopped --name powercontrol viklion/powercontrol:latest
# 设置指定user运行（-u uid:gid）
        </code>
    </pre>

    <!-- 第二个代码块 -->
    <h3>2、docker-compose（注意检查缩进）</h3>
    <pre>
        <button class="copy-btn" data-clipboard-target="#code-block-3">复制代码</button>
        <code id="code-block-3">
services:
  powercontrol:
    image: viklion/powercontrol:latest
    container_name: powercontrol
    volumes:
      - /your/path:/app/data
    environment:
      - WEB_PORT=7678
      - WEB_KEY=yourkey
    # 默认root用户运行，去掉下行的#，设置指定user运行（uid:gid）
    #user: 1000:100
    restart: unless-stopped
    network_mode: host
        </code>
    </pre>

    <!-- 第三个代码块 -->
    <h3>3、homeassistant configuration.yaml（注意检查缩进）</h3>
    <pre>
        <button class="copy-btn" data-clipboard-target="#code-block-4">复制代码</button>
        <code id="code-block-4">
shell_command:
  ha_wol_pc: "curl http://192.168.2.75:1856/wol?key=1111"
  ha_shutdown_pc: "curl http://192.168.2.75:1856/shutdown?key=1111"

input_text:
  powercontrol_state:
    name: powercontrol_state
    initial: "off"

sensor:
  - platform: rest
    name: "powercontrol_pc_state"
    resource: "http://192.168.2.75:1856/ping?key=1111"
    method: GET
    scan_interval: 60
    value_template: "{{ value_json.device_status }}"

switch:
  - platform: template
    switches:
      my_pc:
        friendly_name: "电脑"
        unique_id: "my_pc_001"
        icon_template: mdi:desktop-tower-monitor
        value_template: "{{ states('input_text.powercontrol_state') == 'on' }}"
        turn_on:
          - service: shell_command.ha_wol_pc
          - service: input_text.set_value
            target:
              entity_id: input_text.powercontrol_state
            data:
              value: "on"
        turn_off:
          - service: shell_command.ha_shutdown_pc
          - service: input_text.set_value
            target:
              entity_id: input_text.powercontrol_state
            data:
              value: "off"
        </code>
    </pre>

    <!-- 第四个代码块 -->
    <h3>4、homeassistant automations.yaml（注意检查缩进）</h3>
    <pre>
        <button class="copy-btn" data-clipboard-target="#code-block-5">复制代码</button>
        <code id="code-block-5">
- id: '20250108'
  alias: 更新电脑在线状态
  trigger:
    - platform: time_pattern
      minutes: "/1"
  condition:
    - condition: template
      value_template: "{{ states('sensor.powercontrol_pc_state') != states('input_text.powercontrol_state') }}"
  action:
    - service: input_text.set_value
      target:
        entity_id: input_text.powercontrol_state
      data:
        value: "{{ states('sensor.powercontrol_pc_state') }}"
        </code>
    </pre>
{% endraw %}
</body>
</html>